/** Factory class --------------------------**/
/** Is the base class of any ressource factory
**/

#ifndef FACTORY_H_
#define FACTORY_H_

#include <string>
#include <map>
#include "Prototype.h"

namespace BPL
{
template <class T, class Key=std::string> class Factory
{
    static std::map<Key, Prototype<T>* > mp_ressources;
public :

    static void registe(const Key& key, Prototype<T>* obj)
    {
        if(mp_ressources.find(key)==mp_ressources.end())
        {
               mp_ressources[key]=obj;
        }
    }

    Prototype<T>* load(const Key& key)
    {
        Prototype<T>* tmp=0;
        typename std::map<Key, Prototype<T>*>::iterator it=mp_ressources.find(key);

        if(it!=mp_ressources.end())
        {
            tmp=((*it).second)->Clone();
        }

        return tmp;
    }

};
}

#endif
